{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=3080
  Verdict: Accepted
}
uses SysUtils, Math;
 
var
	n,ans,p1,p2,kk,t2,t1:int64;
	f:boolean;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n);
ans:=round(1e9);
f:=true;
p2:=n;
read(n);
p1:=n;
read(n);
kk:=3;
t2:=-1;
t1:=-1;
while n<>0 do begin
	if (p1>p2) and (p1>n) then
		if (t1<0) or (t2<0) then begin
			t2:=t1;
			t1:=kk;	
		end else begin
			ans:=min(ans,t1-t2);
			f:=false;
			t2:=t1;
			t1:=kk;
		end;
	p2:=p1;
	p1:=n;
	read(n);
	inc(kk);
end;
if (t1>0) and (t2>0) then begin
	ans:=min(ans,t1-t2);
	f:=false;
end;
if f then ans:=0;
write(ans);
end.